package com.example.algorithm.greedy;

import java.util.Arrays;

/**
 * @author : zhy
 * @since : 2022/8/25
 * 分发饼干
 */
public class Distribute {

    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int max=0;
        int flag=0;
        int lenG=g.length;
        int lenS=s.length;
        for(int i=0;i<lenG;i++)
        {
            for(int j=flag;j<lenS;j++)
            {
                if(g[i]<=s[j])
                {
                    flag=j+1;
                    max++;
                    break;
                }
            }
        }
        return max;
    }

    public static void main(String[] args) {
        Distribute distribute = new Distribute();
        int []g={1,2,3};
        int []s={1,1};
        int contentChildren = distribute.findContentChildren(g, s);
        System.out.println(contentChildren);
    }
}
